/**
*   Show the Items of header  (servlet)
*   4/6/2012
*/

package org.buptjunjun.servlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class ShowHeaders extends HttpServlet
{
    public void doGet(HttpServletRequest request,
                  	 HttpServletResponse response) 
					 throws IOException ,ServletException
	{
		response.setContentType("text/html");
		
		PrintWriter out = response.getWriter();
		out.println("<HTML><BODY>");
		
		out.println("method: "+ request.getMethod() +"<BR>");
		out.println("URL: " + request.getRequestURI() +"<BR>");
		out.println("Protocol: " + request.getProtocol() +"<BR>");
		
		//get the names of all parameters;
		Enumeration headerNames = request.getHeaderNames();			  
		//print the name of each of the Params;
		while(headerNames.hasMoreElements())
		{
			//get the name of each param
			String headerName = (String)headerNames.nextElement();   
			//get the param values of certain param
			String headerValues = request.getHeader(headerName);
			if(headerValues != null)
			{
			   out.println(headerName+" : " + headerValues);
			   out.println("<BR>");
			}
		}
		
		out.println("</BODY></HTML>");
	
	}
	
    public void doPost(HttpServletRequest request,
	              HttpServletResponse response)
				  throws IOException, ServletException
	{
	    doGet(request,response);
	}

}